package logic

import (
	"context"
	"errors"
	"local-life/cache"

	"local-life/liferpc/internal/svc"
	"local-life/liferpc/liferpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CartDelLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCartDelLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CartDelLogic {
	return &CartDelLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CartDelLogic) CartDel(in *liferpc.CartDelRequest) (*liferpc.CartDelResponse, error) {
	// todo: add your logic here and delete this line
	if cache.CartDel(int(in.UserID), int(in.GoodID)) != nil {
		return nil, errors.New("删除失败")
	}
	return &liferpc.CartDelResponse{
		Success: true,
		Data:    "删除成功",
	}, nil
}
